//装载问题
#include <iostream>
#include <algorithm>
using namespace std;
const int MAXN=40;
int n,c;
int w[MAXN+1];
int maxs=0;
void search(int s,int next){
    if (next>n) return;
    for(int j=next;j<=n;j++){
        s+=w[j];
        if (s<=c&&s>maxs) maxs=s;
        if (s>=c) break;//增加剪枝
        if (s+w[j+1]<=c) search(s,j+1);
        s-=w[j];
    }
}
int main(){
    cin>>n>>c;
    for(int i=1;i<=n;i++){
        cin>>w[i];
    }
    sort(w,w+n+1);//便于搜索剪枝
    search(0,1);
    cout<<maxs;
}
